package org.example.lease.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import org.example.lease.model.entities.ViewAppointment;
import org.example.lease.model.enums.AppointmentStatus;
import org.example.lease.model.result.Result;
import org.example.lease.service.ViewAppointmentService;
import org.example.lease.vo.appointment.AppointmentQueryVo;
import org.example.lease.vo.appointment.AppointmentVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;

/**
 * @author 宋孟林
 * @description
 * @date: 2025/5/24 14:14
 */
@Tag(name = "预约看房管理")
@RestController
@Slf4j
@RequestMapping("/admin/appointment")
public class ViewAppointmentController {
    @Resource
    private ViewAppointmentService viewAppointmentService;

    @Operation(summary = "分页查询预约信息")
    @GetMapping("/page")
    public Result<IPage<AppointmentVo>> page(@RequestParam("current") Long current,
                                             @RequestParam("size") Long size,
                                             AppointmentQueryVo appointmentQueryVo) {
        Page<AppointmentVo> page = new Page<>(current, size);
        IPage<AppointmentVo> appointmentVoIPage = viewAppointmentService.selectAppointmentVoByQuery(page, appointmentQueryVo);
        return Result.ok(appointmentVoIPage);
    }

    @Operation(summary = "根据id更新预约状态")
    @PostMapping("updateStatusById")
    public Result<?> updateStatusById(@RequestParam Long id, @RequestBody AppointmentStatus appointmentStatus) {
        viewAppointmentService.update(null, Wrappers.lambdaUpdate(ViewAppointment.class)
                .eq(ViewAppointment::getId, id).set(ViewAppointment::getAppointmentStatus, appointmentStatus));
        return Result.ok();
    }


}
